class Solution {
    public String convert(String s, int numRows) {
        StringBuffer sb = new StringBuffer();
        for (int i = 0; i < numRows; i++) {
            boolean flag = i != numRows - 1;
            for (int j = i; j < s.length(); j += Math.max(1, (flag ? numRows - 1 - i : i) * 2), flag = (i == 0 || i == numRows - 1) == flag) {
                sb.append(s.charAt(j));
            }
        }
        return sb.toString();
    }
}